#
# Created: 2025-07-27

from pycirclize import Circos  # 导入pycirclize库中的Circos类
import pandas as pd  # 导入pandas库

# 创建矩阵数据（10行10列）
row_names = list("ABCDEFGHIJ")  # 行名称
col_names = row_names  # 列名称与行名称相同
matrix_data = [  # 矩阵数据
    [51, 115, 60, 17, 120, 126, 115, 179, 127, 114],
    [108, 138, 165, 170, 85, 221, 75, 107, 203, 79],
    [108, 54, 72, 123, 84, 117, 106, 114, 50, 27],
    [62, 134, 28, 185, 199, 179, 74, 94, 116, 108],
    [211, 114, 49, 55, 202, 97, 10, 52, 99, 111],
    [87, 6, 101, 117, 124, 171, 110, 14, 175, 164],
    [167, 99, 109, 143, 98, 42, 95, 163, 134, 78],
    [88, 83, 136, 71, 122, 20, 38, 264, 225, 115],
    [145, 82, 87, 123, 121, 55, 80, 32, 50, 12],
    [122, 109, 84, 94, 133, 75, 71, 115, 60, 210],
]
matrix_df = pd.DataFrame(matrix_data, index=row_names,
                         columns=col_names)  # 使用pandas创建数据框

# 从矩阵初始化和弦图（也可以直接加载tsv格式的矩阵文件）
circos = Circos.initialize_from_matrix(
    matrix_df,
    space=3,  # 每个扇形之间的间隔
    r_lim=(93, 100),  # 设置半径范围
    cmap="tab10",  # 颜色映射
    ticks_interval=500,  # 刻度间隔
    label_kws=dict(r=94, size=12, color="white"),  # 标签参数
)

print(matrix_df)  # 打印矩阵数据框
fig = circos.plotfig()  # 绘制和弦图
fig.savefig("chord_diagram.png", dpi=300)  # 保存为 PNG
fig.savefig("chord_diagram.svg")           # 保存为矢量图 SVG
fig.show()